/*
 * SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 *
 * SPDX-License-Identifier: MulanPSL-2.0
 */
#![allow(
    dead_code,
    unused_variables,
    mutable_transmutes,
    non_camel_case_types,
    non_snake_case,
    non_upper_case_globals,
    unused_assignments,
    unused_mut
)]

use crate::common::*;

pub const ENOENT: libc::c_int = 2;
pub const ENTRY_TYPE_QUERIED: libc::c_int = 1;
pub const ENTRY_TYPE_FRONTEND: libc::c_int = 2;
pub const ENTRY_TYPE_ANY: libc::c_int = 0;
pub const _SC_LOGIN_NAME_MAX: libc::c_int = 71;

extern "C" {
    fn sudo_gr_delref(_: *mut group);
    fn sudo_getgrouplist2_v1(
        name: *const libc::c_char,
        basegid: gid_t,
        groupsp: *mut *mut gid_t,
        ngroupsp: *mut libc::c_int,
    ) -> libc::c_int;
    fn sudo_gidlist_delref(_: *mut gid_list);
    fn sudo_get_gidlist(pw: *const passwd, type_0: libc::c_uint) -> *mut gid_list;
    fn sysconf(__name: libc::c_int) -> libc::c_long;
    fn reallocarray(__ptr: *mut libc::c_void, __nmemb: size_t, __size: size_t)
        -> *mut libc::c_void;
    static mut sudo_user: sudo_user;
    fn getgrnam(__name: *const libc::c_char) -> *mut group;
    fn sudo_getgrgid(_: gid_t) -> *mut group;
    fn getgrgid(__gid: __gid_t) -> *mut group;
    fn sudo_debug_printf2_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        level: libc::c_int,
        fmt: *const libc::c_char,
        _: ...
    );
    fn __errno_location() -> *mut libc::c_int;
    static mut sudoers_subsystem_ids: [libc::c_uint; 0];
    fn calloc(_: libc::c_ulong, _: libc::c_ulong) -> *mut libc::c_void;
    fn strlen(_: *const libc::c_char) -> libc::c_ulong;
    fn memcpy(_: *mut libc::c_void, _: *const libc::c_void, _: libc::c_ulong) -> *mut libc::c_void;
    fn getpwnam(__name: *const libc::c_char) -> *mut passwd;
    fn getpwuid(__uid: __uid_t) -> *mut passwd;
}

#[derive(Clone)]
#[repr(C)]
pub struct cache_item_gr {
    pub cache: cache_item,
    pub gr: group,
}

#[derive(Clone)]
#[repr(C)]
pub struct cache_item_gidlist {
    pub cache: cache_item,
    pub gidlist: gid_list,
}

#[derive(Clone)]
#[repr(C)]
pub struct cache_item_pw {
    pub cache: cache_item,
    pub pw: passwd,
}

#[derive(Clone)]
#[repr(C)]
pub struct cache_item_grlist {
    pub cache: cache_item,
    pub grlist: group_list,
}

#[no_mangle]
pub unsafe extern "C" fn sudo_make_pwitem(
    mut uid: uid_t,
    mut name: *const libc::c_char,
) -> *mut cache_item {
    let mut cp: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut pw_shell: *const libc::c_char = std::ptr::null::<libc::c_char>();
    let mut nsize: size_t = 0;
    let mut psize: size_t = 0;
    let mut csize: size_t = 0;
    let mut gsize: size_t = 0;
    let mut dsize: size_t = 0;
    let mut ssize: size_t = 0;
    let mut total: size_t = 0;
    let mut pwitem: *mut cache_item_pw = std::ptr::null_mut::<cache_item_pw>();
    let mut pw: *mut passwd = std::ptr::null_mut::<passwd>();
    let mut newpw: *mut passwd = std::ptr::null_mut::<passwd>();
    debug_decl!(SUDOERS_DEBUG_NSS!());

    pw = if !name.is_null() {
        getpwnam(name)
    } else {
        getpwuid(uid)
    };
    if pw.is_null() {
        *__errno_location() = ENOENT as libc::c_int;
        debug_return_ptr!(std::ptr::null_mut::<cache_item>());
    }

    pw_shell = if ((*pw).pw_shell).is_null()
        || *((*pw).pw_shell).offset(0 as libc::c_int as isize) as libc::c_int == '\u{0}' as i32
    {
        b"/bin/sh\0" as *const u8 as *const libc::c_char
    } else {
        (*pw).pw_shell
    };

    ssize = 0 as libc::c_int as size_t;
    dsize = ssize;
    gsize = dsize;
    csize = gsize;
    psize = csize;
    nsize = psize;
    total = ::std::mem::size_of::<cache_item_pw>() as libc::c_ulong;

    if !((*pw).pw_name).is_null() {
        nsize = (strlen((*pw).pw_name)).wrapping_add(1 as libc::c_int as libc::c_ulong);
        total = (total as libc::c_ulong).wrapping_add(nsize) as size_t as size_t;
    }
    if !((*pw).pw_passwd).is_null() {
        psize = (strlen((*pw).pw_passwd)).wrapping_add(1 as libc::c_int as libc::c_ulong);
        total = (total as libc::c_ulong).wrapping_add(psize) as size_t as size_t;
    }
    if !((*pw).pw_gecos).is_null() {
        gsize = (strlen((*pw).pw_gecos)).wrapping_add(1 as libc::c_int as libc::c_ulong);
        total = (total as libc::c_ulong).wrapping_add(gsize) as size_t as size_t;
    }
    if !((*pw).pw_dir).is_null() {
        dsize = (strlen((*pw).pw_dir)).wrapping_add(1 as libc::c_int as libc::c_ulong);
        total = (total as libc::c_ulong).wrapping_add(dsize) as size_t as size_t;
    }

    ssize = (strlen(pw_shell)).wrapping_add(1 as libc::c_int as libc::c_ulong);
    total = (total as libc::c_ulong).wrapping_add(ssize) as size_t as size_t;
    if !name.is_null() {
        total = (total as libc::c_ulong)
            .wrapping_add((strlen(name)).wrapping_add(1 as libc::c_int as libc::c_ulong))
            as size_t as size_t;
    }

    pwitem = calloc(1 as libc::c_int as libc::c_ulong, total) as *mut cache_item_pw;
    if pwitem.is_null() {
        sudo_debug_printf!(
            SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
            b"unable to allocate memory\0" as *const u8 as *const libc::c_char
        );
        debug_return_ptr!(std::ptr::null_mut::<cache_item>());
    }
    newpw = &mut (*pwitem).pw;

    memcpy(
        newpw as *mut libc::c_void,
        pw as *const libc::c_void,
        ::std::mem::size_of::<passwd>() as libc::c_ulong,
    );
    cp = pwitem.offset(1 as libc::c_int as isize) as *mut libc::c_char;

    if !((*pw).pw_name).is_null() {
        memcpy(
            cp as *mut libc::c_void,
            (*pw).pw_name as *const libc::c_void,
            nsize,
        );
        let fresh0 = &mut (*newpw).pw_name;
        *fresh0 = cp;
        cp = cp.offset(nsize as isize);
    }
    if !((*pw).pw_passwd).is_null() {
        memcpy(
            cp as *mut libc::c_void,
            (*pw).pw_passwd as *const libc::c_void,
            psize,
        );
        let fresh1 = &mut (*newpw).pw_passwd;
        *fresh1 = cp;
        cp = cp.offset(psize as isize);
    }
    if !((*pw).pw_gecos).is_null() {
        memcpy(
            cp as *mut libc::c_void,
            (*pw).pw_gecos as *const libc::c_void,
            gsize,
        );
        let fresh2 = &mut (*newpw).pw_gecos;
        *fresh2 = cp;
        cp = cp.offset(gsize as isize);
    }
    if !((*pw).pw_dir).is_null() {
        memcpy(
            cp as *mut libc::c_void,
            (*pw).pw_dir as *const libc::c_void,
            dsize,
        );
        let fresh3 = &mut (*newpw).pw_dir;
        *fresh3 = cp;
        cp = cp.offset(dsize as isize);
    }

    memcpy(
        cp as *mut libc::c_void,
        pw_shell as *const libc::c_void,
        ssize,
    );
    let fresh4 = &mut (*newpw).pw_shell;
    *fresh4 = cp;
    cp = cp.offset(ssize as isize);

    if !name.is_null() {
        memcpy(
            cp as *mut libc::c_void,
            name as *const libc::c_void,
            (strlen(name)).wrapping_add(1 as libc::c_int as libc::c_ulong),
        );
        let fresh5 = &mut (*pwitem).cache.k.name;
        *fresh5 = cp;
    } else {
        (*pwitem).cache.k.uid = (*pw).pw_uid;
    }

    let fresh6 = &mut (*pwitem).cache.d.pw;
    *fresh6 = newpw;
    (*pwitem).cache.refcnt = 1 as libc::c_int as libc::c_uint;

    debug_return_ptr!(&mut (*pwitem).cache as *mut cache_item);
}

#[no_mangle]
pub fn sudo_make_gritem(mut gid: gid_t, mut name: *const libc::c_char) -> *mut cache_item {
    let mut cp: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut nsize: size_t = 0;
    let mut psize: size_t = 0;
    let mut nmem: size_t = 0;
    let mut total: size_t = 0;
    let mut len: size_t = 0;
    let mut gritem: *mut cache_item_gr = std::ptr::null_mut::<cache_item_gr>();
    let mut gr: *mut group = std::ptr::null_mut::<group>();
    let mut newgr: *mut group = std::ptr::null_mut::<group>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_NSS!());

        gr = if !name.is_null() {
            getgrnam(name)
        } else {
            getgrgid(gid)
        };
        if gr.is_null() {
            *__errno_location() = ENOENT as libc::c_int;
            debug_return_ptr!(std::ptr::null_mut::<cache_item>());
        }

        nmem = 0 as libc::c_int as size_t;
        psize = nmem;
        nsize = psize;
        total = ::std::mem::size_of::<cache_item_gr>() as libc::c_ulong;
        if !((*gr).gr_name).is_null() {
            nsize = (strlen((*gr).gr_name)).wrapping_add(1 as libc::c_int as libc::c_ulong);
            total = (total as libc::c_ulong).wrapping_add(nsize) as size_t as size_t;
        }
        if !((*gr).gr_passwd).is_null() {
            psize = (strlen((*gr).gr_passwd)).wrapping_add(1 as libc::c_int as libc::c_ulong);
            total = (total as libc::c_ulong).wrapping_add(psize) as size_t as size_t;
        }

        if !((*gr).gr_mem).is_null() {
            nmem = 0 as libc::c_int as size_t;
            while !(*((*gr).gr_mem).offset(nmem as isize)).is_null() {
                total = (total as libc::c_ulong).wrapping_add(
                    (strlen(*((*gr).gr_mem).offset(nmem as isize)))
                        .wrapping_add(1 as libc::c_int as libc::c_ulong),
                ) as size_t as size_t;
                nmem = nmem.wrapping_add(1);
            }
            nmem = nmem.wrapping_add(1);
            total = (total as libc::c_ulong).wrapping_add(
                (::std::mem::size_of::<*mut libc::c_char>() as libc::c_ulong).wrapping_mul(nmem),
            ) as size_t as size_t;
        }
        if !name.is_null() {
            total = (total as libc::c_ulong)
                .wrapping_add((strlen(name)).wrapping_add(1 as libc::c_int as libc::c_ulong))
                as size_t as size_t;
        }

        gritem = calloc(1 as libc::c_int as libc::c_ulong, total) as *mut cache_item_gr;

        if gritem.is_null() {
            sudo_debug_printf!(
                SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                b"unable to allocate memory\0" as *const u8 as *const libc::c_char
            );
            debug_return_ptr!(std::ptr::null_mut::<cache_item>());
        }

        newgr = &mut (*gritem).gr;
        memcpy(
            newgr as *mut libc::c_void,
            gr as *const libc::c_void,
            ::std::mem::size_of::<group>() as libc::c_ulong,
        );
        cp = gritem.offset(1 as libc::c_int as isize) as *mut libc::c_char;

        if !((*gr).gr_mem).is_null() {
            let fresh7 = &mut (*newgr).gr_mem;
            *fresh7 = cp as *mut *mut libc::c_char;
            cp = cp.offset(
                (::std::mem::size_of::<*mut libc::c_char>() as libc::c_ulong).wrapping_mul(nmem)
                    as isize,
            );
            nmem = 0 as libc::c_int as size_t;
            while !(*((*gr).gr_mem).offset(nmem as isize)).is_null() {
                len = (strlen(*((*gr).gr_mem).offset(nmem as isize)))
                    .wrapping_add(1 as libc::c_int as libc::c_ulong);
                memcpy(
                    cp as *mut libc::c_void,
                    *((*gr).gr_mem).offset(nmem as isize) as *const libc::c_void,
                    len,
                );
                let fresh8 = &mut *((*newgr).gr_mem).offset(nmem as isize);
                *fresh8 = cp;
                cp = cp.offset(len as isize);
                nmem = nmem.wrapping_add(1);
            }
            let fresh9 = &mut *((*newgr).gr_mem).offset(nmem as isize);
            *fresh9 = std::ptr::null_mut::<libc::c_char>();
        }

        if !((*gr).gr_passwd).is_null() {
            memcpy(
                cp as *mut libc::c_void,
                (*gr).gr_passwd as *const libc::c_void,
                psize,
            );
            let fresh10 = &mut (*newgr).gr_passwd;
            *fresh10 = cp;
            cp = cp.offset(psize as isize);
        }
        if !((*gr).gr_name).is_null() {
            memcpy(
                cp as *mut libc::c_void,
                (*gr).gr_name as *const libc::c_void,
                nsize,
            );
            let fresh11 = &mut (*newgr).gr_name;
            *fresh11 = cp;
            cp = cp.offset(nsize as isize);
        }

        if !name.is_null() {
            memcpy(
                cp as *mut libc::c_void,
                name as *const libc::c_void,
                (strlen(name)).wrapping_add(1 as libc::c_int as libc::c_ulong),
            );
            let fresh12 = &mut (*gritem).cache.k.name;
            *fresh12 = cp;
        } else {
            (*gritem).cache.k.gid = (*gr).gr_gid;
        }
        let fresh13 = &mut (*gritem).cache.d.gr;
        *fresh13 = newgr;
        (*gritem).cache.refcnt = 1 as libc::c_int as libc::c_uint;

        debug_return_ptr!(&mut (*gritem).cache as *mut cache_item);
    } //unsafe
}

#[no_mangle]
pub fn sudo_make_gidlist_item(
    mut pw: *const passwd,
    mut unused1: *const *mut libc::c_char,
    mut type_0: libc::c_uint,
) -> *mut cache_item {
    let mut cp: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut nsize: size_t = 0;
    let mut total: size_t = 0;
    let mut glitem: *mut cache_item_gidlist = std::ptr::null_mut::<cache_item_gidlist>();
    let mut gidlist: *mut gid_list = std::ptr::null_mut::<gid_list>();
    let mut gids: *mut gid_t = std::ptr::null_mut::<gid_t>();
    let mut i: libc::c_int = 0;
    let mut ngids: libc::c_int = 0;
    unsafe {
        debug_decl!(SUDOERS_DEBUG_NSS!());

        if type_0 != ENTRY_TYPE_QUERIED as libc::c_int as libc::c_uint
            && pw == sudo_user.pw
            && !(sudo_user.gids).is_null()
        {
            gids = sudo_user.gids;
            ngids = sudo_user.ngids;
            sudo_user.gids = std::ptr::null_mut::<gid_t>();
            sudo_user.ngids = 0 as libc::c_int;
            type_0 = ENTRY_TYPE_QUERIED as libc::c_int as libc::c_uint;
        } else {
            type_0 = ENTRY_TYPE_QUERIED as libc::c_int as libc::c_uint;
            if sudo_user.max_groups > 0 as libc::c_int {
                ngids = sudo_user.max_groups;
                gids = reallocarray(
                    std::ptr::null_mut::<libc::c_void>(),
                    ngids as size_t,
                    ::std::mem::size_of::<gid_t>() as libc::c_ulong,
                ) as *mut gid_t;
                if gids.is_null() {
                    sudo_debug_printf!(
                        SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                        b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                    );
                    debug_return_ptr!(std::ptr::null_mut::<cache_item>());
                }
                sudo_getgrouplist2_v1((*pw).pw_name, (*pw).pw_gid, &mut gids, &mut ngids);
            } else {
                gids = std::ptr::null_mut::<gid_t>();
                if sudo_getgrouplist2_v1((*pw).pw_name, (*pw).pw_gid, &mut gids, &mut ngids)
                    == -(1 as libc::c_int)
                {
                    sudo_debug_printf!(
                        SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                        b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                    );
                    debug_return_ptr!(std::ptr::null_mut::<cache_item>());
                }
            }
        } //else

        if ngids <= 0 as libc::c_int {
            free(gids as *mut libc::c_void);
            *__errno_location() = ENOENT as libc::c_int;
            debug_return_ptr!(std::ptr::null_mut::<cache_item>());
        }

        nsize = (strlen((*pw).pw_name)).wrapping_add(1 as libc::c_int as libc::c_ulong);
        total = (::std::mem::size_of::<cache_item_gidlist>() as libc::c_ulong).wrapping_add(nsize);
        total = (total as libc::c_ulong).wrapping_add(
            (::std::mem::size_of::<*mut gid_t>() as libc::c_ulong)
                .wrapping_mul(ngids as libc::c_ulong),
        ) as size_t as size_t;
        glitem = calloc(1 as libc::c_int as libc::c_ulong, total) as *mut cache_item_gidlist;
        if glitem.is_null() {
            sudo_debug_printf!(
                SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                b"unable to allocate memory\0" as *const u8 as *const libc::c_char
            );
            free(gids as *mut libc::c_void);
            debug_return_ptr!(std::ptr::null_mut::<cache_item>());
        }

        gidlist = &mut (*glitem).gidlist;
        cp = glitem.offset(1 as libc::c_int as isize) as *mut libc::c_char;
        let fresh14 = &mut (*gidlist).gids;
        *fresh14 = cp as *mut gid_t;
        cp = cp.offset(
            (::std::mem::size_of::<gid_t>() as libc::c_ulong).wrapping_mul(ngids as libc::c_ulong)
                as isize,
        );

        memcpy(
            cp as *mut libc::c_void,
            (*pw).pw_name as *const libc::c_void,
            nsize,
        );
        let fresh15 = &mut (*glitem).cache.k.name;
        *fresh15 = cp;
        let fresh16 = &mut (*glitem).cache.d.gidlist;
        *fresh16 = gidlist;
        (*glitem).cache.refcnt = 1 as libc::c_int as libc::c_uint;
        (*glitem).cache.type_0 = type_0;

        i = 0 as libc::c_int;
        while i < ngids {
            *((*gidlist).gids).offset(i as isize) = *gids.offset(i as isize);
            i += 1;
        }

        (*gidlist).ngids = ngids;
        free(gids as *mut libc::c_void);

        debug_return_ptr!(&mut (*glitem).cache as *mut cache_item);
    } //unsafe
}

#[no_mangle]
pub fn sudo_make_grlist_item(
    mut pw: *const passwd,
    mut unused1: *const *mut libc::c_char,
) -> *mut cache_item {
    let mut cp: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut nsize: size_t = 0;
    let mut ngroups: size_t = 0;
    let mut total: size_t = 0;
    let mut len: size_t = 0;
    let mut grlitem: *mut cache_item_grlist = std::ptr::null_mut::<cache_item_grlist>();
    let mut grlist: *mut group_list = std::ptr::null_mut::<group_list>();
    let mut gidlist: *mut gid_list = std::ptr::null_mut::<gid_list>();
    let mut grp: *mut group = std::ptr::null_mut::<group>();
    let mut i: libc::c_int = 0;
    let mut groupname_len: libc::c_int = 0;
    unsafe {
        debug_decl!(SUDOERS_DEBUG_NSS!());

        gidlist = sudo_get_gidlist(pw, ENTRY_TYPE_ANY as libc::c_int as libc::c_uint);
        if gidlist.is_null() {
            sudo_debug_printf!(
                SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                b"no gid list for use %s\0" as *const u8 as *const libc::c_char,
                (*pw).pw_name
            );
            *__errno_location() = ENOENT as libc::c_int;
            debug_return_ptr!(std::ptr::null_mut::<cache_item>());
        }

        groupname_len =
            if sysconf(_SC_LOGIN_NAME_MAX as libc::c_int) as libc::c_int > 32 as libc::c_int {
                sysconf(_SC_LOGIN_NAME_MAX as libc::c_int) as libc::c_int
            } else {
                32 as libc::c_int
            };

        nsize = (strlen((*pw).pw_name)).wrapping_add(1 as libc::c_int as libc::c_ulong);
        total = (::std::mem::size_of::<cache_item_grlist>() as libc::c_ulong).wrapping_add(nsize);
        total = (total as libc::c_ulong).wrapping_add(
            (::std::mem::size_of::<*mut libc::c_char>() as libc::c_ulong)
                .wrapping_mul((*gidlist).ngids as libc::c_ulong),
        ) as size_t as size_t;
        total = (total as libc::c_ulong)
            .wrapping_add((groupname_len * (*gidlist).ngids) as libc::c_ulong)
            as size_t as size_t;

        //start again
        'again: loop {
            let mut RS_flag: bool = false;

            grlitem = calloc(1 as libc::c_int as libc::c_ulong, total) as *mut cache_item_grlist;
            if grlitem.is_null() {
                sudo_debug_printf!(
                    SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                    b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                );
                sudo_gidlist_delref(gidlist);
                debug_return_ptr!(std::ptr::null_mut::<cache_item>());
            }

            grlist = &mut (*grlitem).grlist;
            cp = grlitem.offset(1 as libc::c_int as isize) as *mut libc::c_char;
            let fresh17 = &mut (*grlist).groups;
            *fresh17 = cp as *mut *mut libc::c_char;
            cp = cp.offset(
                (::std::mem::size_of::<*mut libc::c_char>() as libc::c_ulong)
                    .wrapping_mul((*gidlist).ngids as libc::c_ulong) as isize,
            );

            memcpy(
                cp as *mut libc::c_void,
                (*pw).pw_name as *const libc::c_void,
                nsize,
            );
            let fresh18 = &mut (*grlitem).cache.k.name;
            *fresh18 = cp;
            let fresh19 = &mut (*grlitem).cache.d.grlist;
            *fresh19 = grlist;
            (*grlitem).cache.refcnt = 1 as libc::c_int as libc::c_uint;
            cp = cp.offset(nsize as isize);

            //for
            ngroups = 0 as libc::c_int as size_t;
            i = 0 as libc::c_int;

            while i < (*gidlist).ngids {
                grp = sudo_getgrgid(*((*gidlist).gids).offset(i as isize));
                if !grp.is_null() {
                    len = (strlen((*grp).gr_name)).wrapping_add(1 as libc::c_int as libc::c_ulong);
                    if (cp.offset_from(grlitem as *mut libc::c_char) as libc::c_long
                        as libc::c_ulong)
                        .wrapping_add(len)
                        > total
                    {
                        total = (total as libc::c_ulong)
                            .wrapping_add(len.wrapping_add(groupname_len as libc::c_ulong))
                            as size_t as size_t;
                        free(grlitem as *mut libc::c_void);
                        sudo_gr_delref(grp);

                        RS_flag = true;
                        //i += 1;
                        break;
                    }
                    memcpy(
                        cp as *mut libc::c_void,
                        (*grp).gr_name as *const libc::c_void,
                        len,
                    );
                    let fresh20 = ngroups;
                    ngroups = ngroups.wrapping_add(1);
                    let fresh21 = &mut *((*grlist).groups).offset(fresh20 as isize);
                    *fresh21 = cp;
                    cp = cp.offset(len as isize);
                    sudo_gr_delref(grp);
                }
                i += 1;
            }

            if RS_flag {
                continue;
            }

            break 'again;
        }
        //stop again

        (*grlist).ngroups = ngroups as libc::c_int;
        sudo_gidlist_delref(gidlist);

        debug_return_ptr!(&mut (*grlitem).cache as *mut cache_item);
    } //unsafe
}
